package com.wontube.smr.cron;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.wontube.core.cron.IJobs;
import com.wontube.smr.bo.sites.fs.TopMusicObtainBO;
import com.wontube.smr.client.model.po.TopMusic;



/**
 * @author yuechao
 *
 */
public final class ObtainTopMusicJobs implements IJobs {
	private static final Logger logger = LoggerFactory.getLogger(ObtainTopMusicJobs.class);
	
	/* 
	 * @see smr.cron.jobs.IJobs#name()
	 */
	@Override
	public String name() {
		return "obtain-top-music";
	}

	/* 
	 * @see smr.cron.jobs.IJobs#execute()
	 */
	@Override
	public IJobs execute(String[] args) {
		try {
			HashMap<String, ArrayList<TopMusic>> map = TopMusicObtainBO.obtainFromWeb();
			if (logger.isDebugEnabled()) {
				for (Map.Entry<String, ArrayList<TopMusic>> entry : map.entrySet()) {
					logger.debug("obtained {} records from {}", entry.getValue().size(), entry.getKey());
				}
			}
		} catch (IOException e) {
			logger.error(e.toString());
		}
		return this;
	}

}
